package net.cooltain.warhammer.running.window.button;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.Border;

import net.cooltain.warhammer.framework.constant.ConstantPhases;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;

public class PhasesBtn extends JButton implements MouseListener{

	private static final long serialVersionUID = 6662019699032912495L;
	
	protected static Border emptyBorder = BorderFactory.createEmptyBorder();
	protected static Border currentBorder = BorderFactory.createLineBorder(Color.BLUE, 2);
	protected static Border currentOpeBorder = BorderFactory.createLineBorder(Color.RED, 2);
	
	protected int phasesId;
	protected MotionPlayerZone player;
	
	public PhasesBtn(MotionPlayerZone player,String text,int phasesId) {
		super(text);
		this.player = player;
		this.phasesId = phasesId ;
		this.addMouseListener(this);
	}
	
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		if(player.isMyTurn){
			int currentPhases = player.currentPhases;
			if( (phasesId==ConstantPhases.QUEST_PHASES || phasesId==ConstantPhases.BATTLEFIELD_PHASES)
					&& player.isFisrtPlay){
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.gray));
			}else if(currentPhases>this.phasesId){
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.gray));
			}else if(currentPhases==this.phasesId){
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.BLUE,3));
			}else{
				this.setEnabled(true);
				this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
			}
		}else{
			int currentPhases = player.operatePlayer.currentPhases;
			if(currentPhases>this.phasesId){
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.gray));
			}else if(currentPhases==this.phasesId){
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.RED,3));
			}else{
				this.setEnabled(false);
				this.setBorder(BorderFactory.createLineBorder(Color.gray));
			}
		}
		
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
	}


	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}
